package com.example.library.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.library.entity.TeachingForm;
import com.example.library.entity.Teachingquestions;
import com.example.library.mapper.TeachingquestionsMapper;
import com.example.library.service.ITeachingquestionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.util.StringUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhaoyufei
 * @since 2023-08-07
 */
@Service
public class TeachingquestionsServiceImpl extends ServiceImpl<TeachingquestionsMapper, Teachingquestions>
        implements ITeachingquestionsService {

    @Resource
    private TeachingquestionsMapper mapper;

    @Override
    public IPage<Teachingquestions> getPage(TeachingForm teachingForm) {
        IPage iPage = new Page();
        iPage.setCurrent(teachingForm.getPageNum());
        iPage.setSize(teachingForm.getPageSize());
        iPage.setTotal(mapper.selectList(null).size());
        if (!StringUtils.isNullOrEmpty(teachingForm.getLabel())){
            return mapper.selectPage(iPage, new QueryWrapper<Teachingquestions>().like("label", teachingForm.getLabel()));
        }else {
            return mapper.selectPage(iPage,null);
        }
    }

    @Override
    public void deleteById(Integer id) {
        Teachingquestions teachingquestions = new Teachingquestions();
        teachingquestions.setId(id);
        teachingquestions.setIsDeleted("0");
        mapper.updateById(teachingquestions);
    }
}
